/**
 * @(#)IndexController.java, 2017/12/16.
 * <p/>
 * Copyright 2017 Wangzx, Inc. All rights reserved.
 * WANGZX/CONFIDENTIAL. Use is subject to license terms.
 */
package org.wangzx.exercise.controller;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.wangzx.exercise.enums.LoginType;
import org.wangzx.exercise.meta.vo.ItemVO;
import org.wangzx.exercise.meta.vo.UserVO;
import org.wangzx.exercise.service.basic.ItemService;
import org.wangzx.exercise.utils.LoginUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/")
public class IndexController extends BaseController {
    static final private Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    private ItemService itemService;

    @RequestMapping("/")
    public ModelAndView index(HttpServletRequest request) {
        ModelAndView mav = genModelAndView("/tmpl/index");

        UserVO userVO = LoginUtils.loginCheck(request);
        List<ItemVO> voList = itemService.getAllItemVO(userVO);

        logger.info("[op:index] userVO={}, voList={}", JSON.toJSONString(userVO), JSON.toJSONString(voList));

        mav.addObject("user", userVO);
        mav.addObject("data", voList);
        mav.addObject("list", voList);

        return mav;
    }
}
